package com.travelcloud.module.jobs.controller;

import com.travelcloud.framework.utils.JobHandlerUtil;
import com.travelcloud.module.jobs.service.JobService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 定时任务
 *
 * @author Zee
 * @version 1.0
 * @date 2020/9/1
 */
@RestController
@RequestMapping("job")
@Api(tags = "任务管理")
public class JobController {
    @Autowired
    private JobHandlerUtil jobHandler;
    @Autowired
    private JobService jobService;

    @GetMapping("add")
    @ApiOperation(value = "设置定时任务", notes = "设置定时任务")
    public void doJob(String id, String time) {
        jobHandler.addJob(id, time, (key) -> jobService.doJob(key));
    }

    @GetMapping("stop")
    @ApiOperation(value = "停止定时任务", notes = "停止定时任务")
    public void stopJob(String id) {
        jobHandler.stopJobs(new String[]{id});
    }
}
